﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;
using System.IO;

namespace WESNet.DNN.Modules.UserExport
{
    public class Utilities
    {
        public static string CleanseFilename(string fileName, ExportFormats exportFormat)
        {
            string result = "";

            var fileExtension = Consts.FileExtensions[(int)exportFormat];

            if (string.IsNullOrEmpty(fileName))
            {
                result = string.Format("UserExport_{0:" + Consts.DateFormat + "}.{1}", DateTime.Now, fileExtension);
            }
            else
            {
                fileName = Regex.Replace(fileName, @"[^A-Za-z0-9\-_\.]", "_");
                result = string.IsNullOrEmpty(Path.GetExtension(fileName)) ? fileName + "." + fileExtension : fileName;
            }

            return result;
        }
    }
}